from django.shortcuts import render

from django import http
from django.views import View
from django.utils.decorators import method_decorator
# Create your views here.


# 给类视图添加装饰器
# 1. 定义装饰器
def my_decorator(func):
    def wrapper(request,*args,**kwargs, ):
        # 写自己的扩展功能
        print('--添加装饰器--{}'.format(request.method))
        return func(request,*args,**kwargs)
    return wrapper
# 2. 添加装饰器


# 定义类视图
@method_decorator(my_decorator, name='dispatch')
class LoginView(View):

    def get(self,request):
        return http.HttpResponse('这里假装返回Login页面')

    def post(self,request):
        return http.HttpResponse('这里返回的是Login---逻辑')


def index(request):

    # 1. 接受请求对象

    # 2. 返回响应对象
    return http.HttpResponse('假设的登录请求')

def register(request):

    return http.HttpResponse('假设的注册请求')



class RequestView(View):

    # 请求头参数解析
    def post(self,request,mobile):
        headers = request.META
        print(headers)
        print(type(headers))
        print(headers,['HTTP_NAME'])
        return http.HttpResponse('请求头参数')


    # 路径参数
    # def post(self,request,age):
    #     print(age)
    #     print(type(age))
    #     return http.HttpResponse('路径参数')


    # 自定义转换器
    # def post(self,request,mobile):
    #     print(mobile)
    #     print(type(mobile))
    #     return http.HttpResponse('定义转换器')